package com.donate.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.donate.api.entery.DonateUser;
import com.donate.api.entery.PageVo;
import com.donate.api.entery.Result;
import com.donate.api.service.UserManagerService;
import com.donate.dao.DonateUserDao;
@Service("userManagerService")
public class UserManagerServiceImpl implements UserManagerService{

	Logger logger = LoggerFactory.getLogger(UserManagerServiceImpl.class);
	@Autowired
	private DonateUserDao donateUserDao;
	
	@Transactional
	public Result addUser(DonateUser user) {
		Result result = new Result();
		try {
			donateUserDao.saveUser(user);
			result.addOK("OK");
		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			e.printStackTrace();
			result.addError("系统异常");
		}
		return result;
	}

	@Transactional
	public Result testDao(DonateUser user) {
		logger.info("===========测试begin=============");
		Result result = new Result();
		try {
			List<DonateUser> users = new ArrayList<DonateUser>();
			/*users.add(user);
			DonateUser donateUser = new DonateUser();
			donateUser.setUserId(5);
			users.add(donateUser);*/
			List<String> qList = new ArrayList<String>();
			qList.add("00");
			PageVo pageVo=  donateUserDao.findPageBySql("select * from donate_user where sex =?",2,10,qList.toArray());
			result.setData(pageVo);
			result.addOK("OK");
		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			e.printStackTrace();
			result.addError("系统异常");
		}
		logger.info("===========测试end=============");
		return result;
	}

}
